home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / snr53b.zip / SNR503.DOC < prev    next >
Text File  |  1993-05-30  |  68KB  |  1,799 lines

  1.  
  2.  
  3.  
  4.      TITLE:         SNR.EXE   VERSION: 5.03
  5.  
  6.      PURPOSE:       Multi-string simultaneous Search 'N' Replace program
  7.  
  8.      RELEASE DATE:  5/31/93
  9.  
  10.      AUTHOR:        THOMAS A. LUNDIN
  11.                     16267 Hudson Avenue
  12.                     Lakeville, MN 55044
  13.                     day phone: (612) 588-7571
  14.                     nights/weekends: (612) 431-5805
  15.                     CompuServe ID [70523,262]
  16.  
  17.      REGISTRATION:  $50 per copy; volume and site licenses available.
  18.                     Registered version discards the opening shareware
  19.                     compliance screen, and a free multi-window DOS text
  20.                     editor is bundled with the package.
  21.  
  22.                     Registration guarantees technical support; unregistered
  23.                     users will receive support on a time-available basis.
  24.  
  25.                     Fill out and return the ORDER.FRM file along with your
  26.                     payment to register your copy.
  27.  
  28.      DESCRIPTION:   SNR is a multi-string search-and-replace filter. Both
  29.                     text and binary files can be processed by the program.
  30.                     SNR will translate a file of any size that your system
  31.                     can handle.
  32.  
  33.                     Version 5 of SNR brings many new advanced conversion
  34.                     capabilities to the program, such as:
  35.  
  36.                     - wild-card conversion patterns
  37.                     - variable-length conversion patterns
  38.                     - start-of-file and end-of-file conversions
  39.                     - text field padding
  40.                     - table chaining
  41.                     - enhanced context flags
  42.  
  43.                     Up to 2,500 multi-character (m:n) equations can be
  44.                     entered into an SNR table, each of which can be a
  45.                     maximum of 4,999 characters in length. Total conversion
  46.                     space is limited to 64,000 characters. All search-and-
  47.                     replace operations are performed in a single pass.
  48.                     Context flag conversion allows toggling between two
  49.                     different output strings for the same input string.
  50.                     Wild card patterns allow unspecific character strings
  51.                     to be matched and converted.
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                       -1-                     SNR+ VER 5.03
  64.  
  65.  
  66.                                 REVISION HISTORY
  67.  
  68.           5.02 - 5/26/93
  69.           Major rewrite. Added advanced conversion features such as wild
  70.           card pattern matching, variable-length patterns, field padding,
  71.           and so on. Allow file names to contain DOS wild cards, also.
  72.           Allow multiple-table chaining on the command line. Allow output
  73.           file subdirectory specification. Greatly expanded program
  74.           capacities. Allow 16 context flags. Change default bit-masking
  75.           from 7-level to 8-level as this is the more harmless option.
  76.  
  77.           4.0 - 7/19/90
  78.           Removed OS/2 compatibility. Nobody used it. Allow 256 1:1
  79.           equations to be loaded in addition to 50 m:n equations. Added
  80.           context flag.
  81.  
  82.           3.01 - 11/3/89
  83.           Program recompiled for family mode, meaning it will run as-is
  84.           under DOS, OS/2 real mode, and OS/2 protected mode.
  85.  
  86.           Also improved I/O throughput on fast disk drives.
  87.  
  88.           3.0 - 9/27/89
  89.           The program has been completely rewritten. The pesky bugs that
  90.           were present in versions 1.5 and 2.0 have been eliminated.
  91.  
  92.           All binary characters INCLUDING NULLS can now be searched and
  93.           replaced. Nulls can also be entered as part of a larger search-
  94.           and-replace equation.
  95.  
  96.           An automatic "bit-stripping" feature has been added which removes
  97.           the high-order bits from input characters, forcing 8-bit codes
  98.           into 7-bit ASCII. The feature can be selectively disabled for
  99.           binary files.
  100.  
  101.           The equation length has been increased to 200 characters, which
  102.           can be split into search and replace sides of any length, as long
  103.           as the total does not exceed 200.
  104.  
  105.           Equations no longer need to be in any specific order.
  106.  
  107.           The average speed of the program has been vastly improved,
  108.           especially for multiple and high-occurrence search and replaces.
  109.  
  110.           The program no longer needs to read itself for runtime
  111.           parameters.
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.                                       -2-                     SNR+ VER 5.03
  126.  
  127.  
  128.                                PROGRAM OPERATION
  129.  
  130.      The command line invocation is:
  131.  
  132.           snr [@]filename ext table[ table2...] [/d] [/opathname] [/r]
  133.  
  134.      1.   "filename" is the name of the DOS file you wish to convert. The
  135.           DOS wildcard characters "*" and "?" are allowed here, and they
  136.           will result in all files matching the name pattern to be
  137.           converted at one time. An at-sign (@) in front of the filename
  138.           indicates that the file contains a list of file names to convert.
  139.           There are two ways of creating the list of file names: the first
  140.           is to use the DOS DIR command and redirect its output to a file,
  141.           like this:
  142.  
  143.                dir *.txt >dirfile
  144.  
  145.           This will create a disk file named "dirfile" which contains a
  146.           directory list of all files with a ".TXT" extension. You can edit
  147.           this file if you want, to weed out certain files you don't want
  148.           and retain the others.
  149.  
  150.           You can also create a list file manually by just creating a file
  151.           with a text editor and typing in the path and file names for each
  152.           of the files you wish converted. Example:
  153.  
  154.                d:\data\test.txt
  155.                c:\bigfiles\tapedat.asc
  156.                c:\windows\win.ini
  157.  
  158.           The converted output files will appear in your current directory.
  159.           You can optionally direct the output to another directory with
  160.           the /o option, explained later.
  161.  
  162.      2.   "ext" is the filename extension you wish to assign each output
  163.           file. The output files are created by adding this extension onto
  164.           the name of the input file. If you are converting multiple input
  165.           files from a DIRLIST, or from a wild card in the command line,
  166.           all of the resulting output files will have the same extension.
  167.           The choice of an extension is important; if you accidentally
  168.           choose an extension which is already used by another file, you
  169.           will overwrite the existing file, losing its data in the process.
  170.           SNR will not warn you of impending overwrites. Use an extension
  171.           which you are sure is unique.
  172.  
  173.           Extensions can be the DOS device names CON, NUL, AUX, and PRN. In
  174.           any of these four cases, an output file is NOT created on disk;
  175.           rather, the output is redirected to the console (CON), nowhere
  176.           (NUL), the rs232 port (AUX), or the printer (PRN). Using CON is
  177.           handy for a quick preview of the conversion process before
  178.           storing it to disk, although if you preview binary files to CON,
  179.           be aware that hex code 1A (DOS end-of-file) will terminate the
  180.           conversion display, perhaps prematurely. (This permature
  181.           termination will NOT occur when you store to disk -- it is an
  182.           artifact of displaying to the console.) Also, some binary
  183.           characters will set the PC speaker beeping when you display to
  184.           the screen.
  185.  
  186.  
  187.                                       -3-                     SNR+ VER 5.03
  188.  
  189.  
  190.  
  191.      3.   "tablename" is the file name and optional path which contains
  192.           your string translation "equations". Although no restrictions are
  193.           placed upon the tablename (aside from conforming to the DOS
  194.           naming format), for sake of clarity it is suggested that you
  195.           adopt a consistent naming scheme for them, (say, with an *.S
  196.           extension). Creating conversion equations is discussed in more
  197.           detail later. You may specify more than one table at a time on
  198.           the command line; the effect of this is that SNR will convert
  199.           your input files through each table in sequence. The contents of
  200.           the output files will be just as if you had run SNR a number of
  201.           times in a row.
  202.  
  203.      4.   "/d" is an option which replaces the original input file with the
  204.           converted data. The extension which you specify on the command
  205.           line is used as a temporary intermediate file until the
  206.           conversion is complete, at which time the program deletes the
  207.           original input file and renames the temporary output file to the
  208.           input name.
  209.  
  210.      5.   "/o" is an option which allows you to place the output files in
  211.           some directory other than the current directory. The /o is
  212.           followed immediately by the name of the directory path (no spaces
  213.           in between).
  214.  
  215.      6.   "/r" is an option used only in conjuction with the /o option; it
  216.           is meaningless by itself. /r forces all of the output files in
  217.           the other directory to retain the same name as the original input
  218.           files. At the end of the conversion run using this option, you
  219.           will have two directories of files with the same names, but the
  220.           data in the files in one of the directories will have been
  221.           converted.
  222.  
  223.      7.   The options /o, /r, and /d may appear in a list file, after the
  224.           name of the file to convert. Example:
  225.  
  226.                d:\data\file.1 /od:\
  227.                d:\data\file.2
  228.                c:\text\may.doc
  229.  
  230.           In the above example, all of the files in the list will be
  231.           converted and stored on the root directory of drive D:. These
  232.           option codes may NOT appear in a list file created by redirecting
  233.           the DOS DIR command to a file.
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.                                       -4-                     SNR+ VER 5.03
  250.  
  251.  
  252.                              COMMAND LINE EXAMPLES
  253.  
  254.      C>snr tstfil.doc txt tst.s
  255.  
  256.           The above command line will convert input file "tstfil.doc"
  257.           through table "tst.s" and create output file "tstfil.txt".
  258.  
  259.      C>snr @dirlist p1 sample.s
  260.  
  261.           The above command line will convert a group of files listed in
  262.           the file "dirlist" through table "sample.s" and create a group of
  263.           output files with extensions of *.p1.
  264.  
  265.      C>snr *.c xxx pass1.s pass2.s pass3.s /d
  266.  
  267.           The above command line will convert a group of files matching the
  268.           DOS file name pattern "*.c" through the three tables "pass1.s",
  269.           "pass2.s" and "pass3.s" in order, and the converted output files
  270.           will replace the original input files. (The temporary
  271.           intermediate files will have an extension of *.xxx.)
  272.  
  273.      C>snr mytest.dat da2 pass1.s /od:\
  274.  
  275.           The above command will convert the input file "mytest.dat"
  276.           through table "pass1.s" and create an outfile named "mytest.da2"
  277.           in the root directory of drive D:.
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.                                       -5-                     SNR+ VER 5.03
  312.  
  313.  
  314.                            CREATING CONVERSION TABLES
  315.  
  316.      SNR tables are ASCII text files which contain the search-and-replace
  317.      equations used by the program. Any word processor or text editing
  318.      program capable of loading and saving plain ASCII text files will be
  319.      sufficient to create conversion tables. (The registered version of SNR
  320.      is bundled with a free multi-window DOS text editor for this purpose.)
  321.  
  322.      Up to 2,500 of these equations can be entered in a single table, and
  323.      each equation can consist of up to 4,999 characters split freely
  324.      between the search side and the replacement side. Blank lines in a
  325.      table will be ignored. The maximum size of a table is limited to
  326.      64,000 characters. These equations will be matched against the input
  327.      file in a single pass, resulting in a converted output file.
  328.  
  329.      EQUATION TYPES
  330.      This manual may refer to certain equation types from time to time. The
  331.      equation types that are handled by SNR are as follows:
  332.  
  333.      1:0  an equation comprising one character on the left side and no
  334.           characters on the right side
  335.      1:1  an equation with one character on the left side and one character
  336.           on the right side
  337.      1:n  an equation with on character on the left side and two or more
  338.           characters on the right side
  339.      m:0  an equation with two or more characters on the left side, and no
  340.           characters on the right side
  341.      m:1  an equation with two or more characters on the left side, and one
  342.           character on the right side
  343.      m:n  an equation with two or more characters on the left side, and two
  344.           or more characters on the right side
  345.  
  346.      FORMAT OF EQUATIONS
  347.      The simplest form of conversion equation consists of literal search
  348.      and replace text separated by an equals sign. A sample 1:1 equation
  349.      would be:
  350.  
  351.           A=a
  352.  
  353.      The above equation would translate an upper-case 'A' to a lower-case
  354.      'a'.
  355.  
  356.      A sample m:n equation would be:
  357.  
  358.           Now is the time=NOW IS THE TIME
  359.  
  360.      The above equation will translate the words "Now is the time" to all
  361.      upper-case. Notice that spaces ARE SIGNIFICANT characters in an
  362.      equation, so don't use them carelessly if you don't mean to have them
  363.      converted.
  364.  
  365.      1:0 and m:0 equations ignore search strings (that is, throw it away on
  366.      output). They are defined simply by leaving out a replacement string,
  367.      like this:
  368.  
  369.           Now is the time=
  370.  
  371.  
  372.  
  373.                                       -6-                     SNR+ VER 5.03
  374.  
  375.  
  376.      If you want to output word spaces at the end of a replacement string,
  377.      but your text editor strips trailing spaces, you can define them as
  378.      hex codes:
  379.  
  380.           Now is the time =NOW IS THE TIME\20
  381.  
  382.      In fact, any hex code can be formed from a backslash followed by two
  383.      hex digits (0-9, a-f, A-F). You'd normally use hex codes to search or
  384.      replace binary characters that can't be generated directly from the
  385.      keyboard. For instance, a carriage return/line feed sequence (CRLF)
  386.      can be specified like this:
  387.  
  388.           \0d\0a\0d\0a=\0d\0a
  389.  
  390.      The above equation will convert two CRLFs in a row to a single CRLF.
  391.  
  392.      SNR RESERVED CHARACTERS
  393.      There are three ASCII characters which MUST be specified as hex codes
  394.      in an SNR equation, since they have special meaning in their normal
  395.      ASCII form. They are:
  396.  
  397.      Backslash (\), which must be entered as \5c
  398.      Equals (=), which must be entered as \3d
  399.      Asterisk (*), which must be entered as \2a
  400.  
  401.      If you forget to follow this notation, you will very likely trigger
  402.      error messages when you attempt to run a conversion.
  403.  
  404.      EXTRA-LONG EQUATIONS
  405.      SNR can handle equation lengths up to 4,999 characters. It's quite
  406.      likely that you will never encounter this limit. Even so, your word
  407.      processor or text editor may have a much smaller limit on the number
  408.      of characters you can enter per line. Should you find you need to
  409.      carry an equation over from one line to the next, you can end a line
  410.      with \+ as the last item in the line, and SNR will automatically add
  411.      the next following line to the same equation. You can have as many
  412.      continuation lines as you need to. Example:
  413.  
  414.           Now is the time for all good men=NOW IS THE TIME    \+
  415.           \20FOR ALL GOOD MEN \ This is all one continued equation
  416.  
  417.      Be mindful that any spaces that occur before the \+ continuation code
  418.      are ignored (an exception to the all-spaces-are-significant rule). Any
  419.      text that appears on the same line after the \+ code is ignored.
  420.  
  421.      ENDING YOUR TABLES
  422.      The end of a table is signified by the end of your equations. You may
  423.      also place a \\E on a line by itself as an end-of-table marker. This
  424.      code is optional, but recommended, since it will prevent SNR from
  425.      inadvertently reading past the intended last line of your equations
  426.      (some word processors may pad their last blocks with garbage or with
  427.      an EOF character, which SNR would attempt to read as the start of a
  428.      new equation). A sure bet that you need to place the \\E code at the
  429.      end of your tables is if SNR occasionally aborts with the message:
  430.  
  431.           Incomplete equation (missing right half):
  432.  
  433.  
  434.  
  435.                                       -7-                     SNR+ VER 5.03
  436.  
  437.  
  438.      ...and you are unable to see that any of your equations is incomplete.
  439.  
  440.      REPEATING CHARACTERS
  441.      SNR provides a shorthand notation for describing a large number of
  442.      repeating characters. Rather than entering an equation that looks like
  443.      this:
  444.  
  445.           AAAAAAAAAAAAAAAAAAAAAAAAA=bbbbbbbbbbbbbbbbbbbb
  446.  
  447.      ...you can describe it like this:
  448.  
  449.           *(25)A=*(20)b
  450.  
  451.      Any character can be repeated using this notation. By changing the
  452.      repeat value in parentheses, you accomplish the same thing as typing
  453.      the repeat character that number of times. NOTE: SNR will actually
  454.      expand a shorthand notation into longhand notation before it begins
  455.      conversion, so make sure you don't inadvertently exceed the 4,999-
  456.      character equation limit with your repeat values.
  457.  
  458.      COMMENTING YOUR EQUATIONS
  459.      SNR provides for writing comments in your tables. Comments can be
  460.      entered in a table as lines by themselves, or set off to the right of
  461.      an equation, as in this example:
  462.  
  463.           \ This is a comment line by itself.
  464.           \   A comment consists of a single backslash
  465.           \   followed by one or more spaces.
  466.  
  467.           \0d\0a=\0d\0a  \ this will ensure that existing CRLF pairs are
  468.                          \ left untouched
  469.           \0d=\0d\0a     \ this equation will convert an isolated CR
  470.                          \ into a CRLF
  471.           \0a=\0d\0a     \ this equation will convert an isolated LF
  472.                          \ into a CRLF
  473.           \\E
  474.  
  475.      When a comment follows an equation on the same line, any spaces that
  476.      occur before the comment are ignored; this is an exception to the all-
  477.      spaces-are-significant rule.
  478.  
  479.      If you're a programmer, or you've used a macro language of some kind,
  480.      you already know the value of program comments. If you're new to the
  481.      field of user programming, you should immediately get into the habit
  482.      of commenting your work. Believe me, you'll be glad you did, because a
  483.      time will come when you have to make a change to a table you created
  484.      months past, and you'll be left scratching your head over it if you
  485.      haven't commented the equations.
  486.  
  487.      EQUATION ORDERING
  488.      SNR will automatically sort equations by length when assembling a
  489.      table in memory. SNR does not process equations in sequential order
  490.      when it converts a file, so the order in which you enter your
  491.      equations is largely immaterial. The exceptions to this rule are when
  492.      using wild card patterns in your equations. This will be explained
  493.      further on.
  494.  
  495.  
  496.  
  497.                                       -8-                     SNR+ VER 5.03
  498.  
  499.  
  500.      Equation processing is completed in a non-recursive fashion. That is,
  501.      once an equation has been matched and a replacement made, the replaced
  502.      data is not sent back for reconversion through another equation. It is
  503.      passed onto the output file once.
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.                                       -9-                     SNR+ VER 5.03
  560.  
  561.  
  562.                                  CONTEXT FLAGS
  563.  
  564.      There are probably instances where you'd like to toggle between two
  565.      different replacement strings for the same search string. The context
  566.      flag allows you to do this. Some example uses would be:
  567.  
  568.      - to compress multiple spaces from a document
  569.      - to ignore any text between two codes
  570.      - to make one code alternate as two different codes
  571.      - to turn all-upper-case text into upper and lower
  572.  
  573.      There are undoubtedly many other uses.
  574.  
  575.      There are 16 context flags which can be used, and each context flag
  576.      has two states: on and off. The context flags are identified by the
  577.      numbers 0-9 and the letters a-f (for a total of 16 individual flags).
  578.  
  579.      When SNR begins execution, the context flags' states are all OFF. A
  580.      flag's state can be tested in a search, and its state can be set or
  581.      reset in a replacement. A context flag is represented in an equation
  582.      by an asterisk, followed by the number or letter of the flag, followed
  583.      by a one or zero (for ON or OFF).
  584.  
  585.      A context flag is the last item entered in a search or replacement
  586.      string. For example:
  587.  
  588.           ABC*00=abc*01
  589.           ABC*01=XYZ*00
  590.  
  591.      In the above two equations, if the string "ABC" is read from the input
  592.      file, and context flag 0 is OFF, then the string "abc" is written to
  593.      the output file, and context flag 0 is set ON. If, on the other hand,
  594.      the string "ABC" is read from the input file, and context flag 0 is
  595.      ON, then the string "XYZ" is written to the output file, and context
  596.      flag 0 is reset OFF. For example, if data from the input file looks
  597.      like this:
  598.  
  599.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  600.  
  601.      ...our small example table would convert it to this:
  602.  
  603.           abcDEFG XYZDEFG abcDEFG XYZDEFG
  604.  
  605.      Context flags are global in scope; this means that each flag is
  606.      accessible by many different equations in one table, and any equation
  607.      can test or set the flags. But beware of unwanted side effects --
  608.      remember that only one equation at a time will control the state of a
  609.      flag, and its state may change between two equations that complement
  610.      each other, resulting in misconversion. For example:
  611.  
  612.           ABC*00=abc*01
  613.           ABC*01=XYZ*00
  614.           EFG*00=efg*01
  615.           EFG*01=ZYX*00
  616.  
  617.  
  618.  
  619.  
  620.  
  621.                                       -10-                    SNR+ VER 5.03
  622.  
  623.  
  624.      The above equations are similar to the previous example, except that
  625.      we have defined two new equations that test and set a single context
  626.      flag. So, given this example input data:
  627.  
  628.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  629.  
  630.      ...the result would convert to this:
  631.  
  632.           abcDZYX abcDZYX abcDZYX abcDZYX
  633.  
  634.      The context flag is being toggled by only two equations:
  635.  
  636.           ABC*00=abc*01  <--- this one
  637.           ABC*01=XYZ*00
  638.           EFG*00=efg*01
  639.           EFG*01=ZYX*00  <--- and this one
  640.  
  641.      If, on the other hand, the input data stream looked like this:
  642.  
  643.           ABCDEFG DEFGABC ABCDEFG DEFGABC
  644.  
  645.      ...the result would look like this:
  646.  
  647.           abcDZYX DefgXYZ abcDZYX DefgXYZ
  648.  
  649.      This conflict between two sets of equations grappling over the same
  650.      context flag can be alleviated by using a different flag number for
  651.      one of the sets:
  652.  
  653.           ABC*00=abc*01
  654.           ABC*01=XYZ*00
  655.           EFG*10=efg*11
  656.           EFG*11=ZYX*10
  657.  
  658.      Now the equations will have independent flags, and the data stream
  659.      will be processed using each equation separately. Now, this data
  660.      stream:
  661.  
  662.           ABCDEFG ABCDEFG ABCDEFG ABCDEFG
  663.  
  664.      ...will be converted to this:
  665.  
  666.           abcDefg XYZDZYX abcDefg XYZDZYX
  667.  
  668.      The thing to keep in mind if you are going to use a context flag is:
  669.      it is OFF when the program begins; you need to enter an equation to
  670.      set it ON; and then you need to have some equation that resets it OFF.
  671.  
  672.      See some of the sample tables for examples in the use of context
  673.      flags.
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.                                       -11-                    SNR+ VER 5.03
  684.  
  685.  
  686.                            SPECIAL CONTEXT FLAG CODES
  687.  
  688.      Certain types of conversions involving context flags can be very
  689.      tedious to define. Take the case of a table whose task is to compress
  690.      two or more adjacent blank spaces into a single space. Using our
  691.      context flags, we would start out by setting a flag when we first
  692.      encounter a space:
  693.  
  694.           \20*00=\20*01
  695.  
  696.      This equation states that if a space is encountered and flag 0 is OFF,
  697.      it will be converted to one space and flag 0 ON. Next we define what
  698.      happens to a space when flag 0 is ON:
  699.  
  700.           \20*01=
  701.  
  702.      This equation states that a space and flag 0 ON, will be ignored. That
  703.      takes care of removing adjacent spaces, but there's something missing.
  704.      The way we have it set up now, EVERY subsequent space will be removed,
  705.      even between words, because we have not defined the case where flag 0
  706.      ever gets set OFF. Without something to set flag 0 OFF, only the
  707.      second equation will hold true.
  708.  
  709.      Since we have defined the case where adjacent spaces will be ignored,
  710.      we need to define the case where some character other than a space
  711.      will reset flag 0 so we can retain the single interword space
  712.      mentioned earlier.
  713.  
  714.      Here's where the tedium comes in. The complete solution is to make
  715.      every character EXCEPT a space set flag 0 OFF, like this:
  716.  
  717.           \00=\00*00
  718.           \01=\01*00
  719.           \02=\02*00
  720.           \03=\03*00
  721.           \04=\04*00
  722.           \05=\05*00
  723.               ...
  724.           \7c=\00*00
  725.           \7d=\00*00
  726.           \7e=\00*00
  727.               ...
  728.  
  729.      ...and so on. Basically, you'd need 255 similar equations to finish
  730.      the task.
  731.  
  732.      Specifically for these types of conversions, SNR provides two
  733.      specialty context flag codes: *ic and *ig.
  734.  
  735.      IGNORE CONSECUTIVE
  736.      The Ignore Consecutive (*ic) flag code is used on the right-hand side
  737.      of the conversion equation. Its purpose is to allow you to specify any
  738.      set of characters that will be ignored when encountered adjacently in
  739.      a data stream. A side benefit of this notation is that SNR will
  740.      automatically generate all of the other flag reset equations that are
  741.      needed to complete the conversion. This vastly reduces the "clutter"
  742.  
  743.  
  744.  
  745.                                       -12-                    SNR+ VER 5.03
  746.  
  747.  
  748.      that would otherwise be present in your table. For instance, here is
  749.      our complete space compression table with the help of the *ic code:
  750.  
  751.           \20=\20*ic\20
  752.  
  753.      That's all there is to it. This equation reads: one space equals one
  754.      space, but ignore consecutive subsequent spaces.
  755.  
  756.      You may define more than one character after the *ic code. In fact,
  757.      you may define as many characters after the *ic code as you care to.
  758.      Each defined character will be ignored if they occur consecutively in
  759.      the data stream after matching the string on the left side of the
  760.      equation. Here's an example:
  761.  
  762.           .\20.\20.=<ldr>*ic\20.
  763.  
  764.      This equation will convert three periods separated by spaces into the
  765.      string <ldr>, and ignore any subsequent consecutive periods and
  766.      spaces. Thus, given the following input data:
  767.  
  768.           Price. . . . . . . . . . . . . . . $25.00
  769.  
  770.      ...the equation would convert it to this:
  771.  
  772.           Price<ldr>$25.00
  773.  
  774.      IGNORE GENERAL
  775.      The other specialty context flag code is the Ignore General (*ig)
  776.      code. This code appears on the right-hand side of an equation and its
  777.      purpose is to cause all characters occurring after the equation to be
  778.      ignored, until an Ignore Cancel (*ix) flag code is encountered.
  779.      Example:
  780.  
  781.           [=*ig
  782.           ]=*ix
  783.  
  784.      These two equations will cause anything falling between a left and
  785.      right square bracket to be ignored, including the brackets themselves.
  786.      Other characters falling outside of these delimiter characters will be
  787.      converted in normal fashion.
  788.  
  789.      The *ig/*ix notation is the quickest way to remove enclosed groups of
  790.      characters from a data stream.
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.                                       -13-                    SNR+ VER 5.03
  808.  
  809.  
  810.                    START-OF-FILE AND END-OF-FILE CONVERSIONS
  811.  
  812.      SNR provides for special conversions to occur before and after normal
  813.      conversion of a data stream. These conversions can be useful in adding
  814.      specific headers or trailers to a file, or in removing portions of the
  815.      beginning and end of a file.
  816.  
  817.      START-OF-FILE CODE
  818.      To trigger an extra conversion at the start of the file, use the \s
  819.      start-of-file code. \s can be entered only as the first character on
  820.      the left-hand side of an equation. It may be used alone, or be
  821.      followed by other characters. Example:
  822.  
  823.           \s=<BEGIN>\0d\0a
  824.  
  825.      The above equation will output the string <BEGIN> as the first item in
  826.      a converted file.
  827.  
  828.           \s=*ic\20
  829.  
  830.      The above equation will ignore any group of consecutive spaces
  831.      occurring at the beginning of a file.
  832.  
  833.           \sNow is the time=
  834.  
  835.      The above equation will ignore the words "Now is the time" when they
  836.      occur at the beginning of a file.
  837.  
  838.      END-OF-FILE CODE
  839.      The \q end-of-file code works similarly to the start-of-file code.
  840.      When it is used in an equation, it will trigger a conversion at the
  841.      very end of a file. \q must always stand by itself on the left-hand
  842.      side of an equation; other characters can not follow it. Example:
  843.  
  844.           \q=[END OF JOB]\0d\0a
  845.  
  846.      The above equation will output the string [END OF JOB] at the very end
  847.      of a converted file.
  848.  
  849.      There is another use for the end-of-file code: to truncate a file when
  850.      a specific character is encountered in the data stream. (This
  851.      character may or may not occur at the true end of the file.) This is
  852.      very useful in cases where some programs add an end-of-file code to
  853.      any files they write, but you don't want them there. For instance, the
  854.      DOS COPY command adds a hex 1A to the end of a combined file when you
  855.      use the "+" operator to copy multiple files into one.
  856.  
  857.      To use this truncation feature, you first need to define a hex
  858.      character that will be recognized specifically as the end-of-file
  859.      character. At the beginning of your table, you must place the
  860.      following setup code:
  861.  
  862.           \\Qxx
  863.  
  864.      ...where "xx" is a two-digit hex code representing the character that
  865.      will trigger the end of file. For instance, the hex value 1A is
  866.      usually recognized as the DOS end-of-file character, so the setup code
  867.  
  868.  
  869.                                       -14-                    SNR+ VER 5.03
  870.  
  871.  
  872.      for that case would be \\Q1A. The next step is to add the \q equation
  873.      to the table to actually process the end-of-file character:
  874.  
  875.           \q=
  876.  
  877.      This particular example will ignore the end-of-file character when it
  878.      is encountered in the data stream, but will terminate processing of
  879.      the file at that point, thus truncating the file.
  880.  
  881.      SPECIAL \s and \q INFORMATION
  882.      Because of the way SNR assembles and categorizes conversion equations,
  883.      any table that contains a \q or \s equation must be of a type that
  884.      contains at least one 1:n or m:n equation (this is an equation type
  885.      that has one or more characters on the left side of the equation, and
  886.      two or more characters on the right side of the equation). \s and \q
  887.      equations will not work in a table that contains only 1:0 or 1:1
  888.      equation types, because the 1:0 and 1:1 tables use a special high-
  889.      speed array translation routine that bypasses the standard equation
  890.      processing routines.
  891.  
  892.      A very simple way to coerce the table processor into categorizing a
  893.      1:1 table as an m:n type is to add the following equation to it:
  894.  
  895.           \80\80=\80\80
  896.  
  897.      This will have no adverse effect on the data stream, since it converts
  898.      two hex 80 characters as two hex 80 characters, but it will have the
  899.      desired effect in SNR's table type categorizing.
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.                                       -15-                    SNR+ VER 5.03
  932.  
  933.  
  934.                                 WILD CARD CODES
  935.  
  936.      Now we get to the fun stuff. While SNR's string conversion
  937.      capabilities are quite powerful on their own, there are inevitably
  938.      times when it is necessary to perform conversions based on ambiguous
  939.      patterns of characters, rather than on literal characters themselves.
  940.      An example here would be if you had a comma-delimited ASCII file that
  941.      was created by a database program, and you noticed that none of the
  942.      phone numbers contained hyphens in them.
  943.  
  944.      It would be quite unfeasible to attempt to literally define all of the
  945.      possible phone numbers without hyphens, and convert them into phone
  946.      numbers with hyphens. You would end up with about 7 million equations
  947.      that went something like this:
  948.  
  949.           2220000=222-0000
  950.           2220001=222-0001
  951.           2220002=222-0002
  952.                ...
  953.           9989997=998-9997
  954.           9989998=998-9998
  955.  
  956.      ...hopefully, you get the idea. To help prevent such exercises in
  957.      futility, SNR provides a number of wild card codes than can be used in
  958.      place of literal characters in conversion equations. The wild card
  959.      codes allow you to search and replace on a set of characters rather
  960.      than on a specific character. For instance, one of the wild card codes
  961.      can be used to search for any of the numeric characters 0-9. Another
  962.      can be used to search for any of the alphabetic characters A-Z.
  963.  
  964.      There are 12 wild card codes in all:
  965.  
  966.           \p   any character
  967.           \n   numeric (0-9)
  968.           \x   full alphabetic (A-Z, a-z)
  969.           \u   upper case alphabetic (A-Z)
  970.           \y   lower case alphabetic (a-z)
  971.           \m   alphanumeric (A-Z, a-z, 0-9)
  972.           \t   punctuation
  973.           \g   non-whitespace
  974.           \o   whitespace (space, tab, return, line feed, vertical tab,
  975.                form feed)
  976.           \z   ASCII-only (c < ASCII 128)
  977.           \v   printable (c > ASCII 31)
  978.           \k   non-printable (c < ASCII 32)
  979.  
  980.      The least restrictive of these, \p, will match any character that is
  981.      encountered in the data stream. The most restrictive of these, \o,
  982.      will match only the set of a few "whitespace" characters. The other
  983.      wild card codes fall between these two extremes, and their associated
  984.      character sets should be fairly straightforward to understand.
  985.  
  986.      On the search side of an equation, a wild card code can be used as a
  987.      straight substitute wherever a literal or hex character would be used.
  988.      For instance, if you wanted to delete any pattern of three numbers
  989.      contained in parentheses, you would enter the following equation:
  990.  
  991.  
  992.  
  993.                                       -16-                    SNR+ VER 5.03
  994.  
  995.  
  996.           (\n\n\n)=
  997.  
  998.      This would delete such occurrences as (612), (000), (123) and so on.
  999.  
  1000.      On the replacement side, however, wild card code usage requires some
  1001.      explanation -- here you can't simply use a wild card code in place of
  1002.      a literal character, as you can in the search string.
  1003.  
  1004.      SNR allows you to rearrange the order of wild card characters during
  1005.      conversion, so we need some method of numbering or otherwise
  1006.      identifying the position of each wild card code in the search string
  1007.      so it can be accessed in any order in the replacement string.
  1008.  
  1009.      This is done easily enough by convention: SNR sequentially numbers the
  1010.      characters in a search string. The leftmost search character is
  1011.      position 0, the next one is position 1, the next is position 2, and so
  1012.      on to the end of the string. The equation:
  1013.  
  1014.           (\n\n\n)=
  1015.  
  1016.      ...contains five characters: The left parenthesis is character 0, the
  1017.      wild card codes are characters 1, 2 and 3, and the right parenthesis
  1018.      is character 4. To use a wild card in a replacement string, then, we
  1019.      define the position of the character we wish to output, like this:
  1020.  
  1021.           (\n\n\n)=\p1\p2\p3
  1022.  
  1023.      The \p code, when used in a replacement string, is always followed by
  1024.      the position number of the character you wish to output. In the above
  1025.      example, when three numbers enclosed in parentheses are encountered in
  1026.      the data stream, the parentheses will be thrown out and only the three
  1027.      numbers will remain (in the same order in which they were defined in
  1028.      the search string). If we change the equation to read like this:
  1029.  
  1030.           (\n\n\n)=\p3\p1\p2
  1031.  
  1032.      ...the three numbers will be output in a different order.
  1033.  
  1034.      Let's return to the example we opened this section with -- that of
  1035.      replacing a series of phone numbers to add a hyphen between the third
  1036.      and fourth digits. Now that we have wild card codes available as a
  1037.      conversion tool, the task becomes much simpler:
  1038.  
  1039.           \n\n\n\n\n\n\n=\p0\p1\p2-\p3\p4\p5\p6
  1040.  
  1041.      Look at the equation: seven numbers on the search side will be
  1042.      replaced by the first three numbers, followed by a hyphen, followed by
  1043.      the last four numbers. If the data stream contained 4315805, the
  1044.      equation would convert it to 431-5805. We could even handle area
  1045.      codes:
  1046.  
  1047.           \n\n\n\n\n\n\n\n\n\n=(\p0\p1\p2) \p3\p4\p5-\p6\p7\p8\p9
  1048.  
  1049.      The equation as written defines 10 numbers on the search side to be
  1050.      replaced by: a left parenthesis, the first three numbers, a right
  1051.      parenthesis and a space, the next three numbers, a hyphen, and the
  1052.  
  1053.  
  1054.  
  1055.                                       -17-                    SNR+ VER 5.03
  1056.  
  1057.  
  1058.      last four numbers. If the data stream contained 6124315805, the
  1059.      equation would convert it to (612) 431-5805.
  1060.  
  1061.      As an aid to equation readability, repeated numbers of wild card codes
  1062.      can use the repeating-character notation described in the first
  1063.      section:
  1064.  
  1065.           *(10)\n=(\p0\p1\p2) \p3\p4\p5-\p6\p7\p8\p9
  1066.  
  1067.      This eliminates the need for you to specifically count how many \n
  1068.      codes you've entered in a search string. The above equation has
  1069.      exactly the same meaning as the previous equation. In a replacement
  1070.      string, you can also use the repeating-character notation, so long as
  1071.      you identify which position is being initially output:
  1072.  
  1073.           *(10)\n=(*(3)\p0) *(3)\p3-*(4)\p6
  1074.  
  1075.      Look at the equation; it defines 10 numeric characters to be replaced
  1076.      by: a left parenthesis, three numeric characters starting at position
  1077.      0, a right parenthsis, a space, three numeric characters starting at
  1078.      position 3, a hyphen, and four numeric characters starting at position
  1079.      6. This is exactly the same equation as the one defined three
  1080.      paragraphs ago, but it is shorter and perhaps easier to read.
  1081.  
  1082.      Which notation you ultimately use -- long or short -- is purely a
  1083.      matter of personal taste and appropriateness for the equation at hand.
  1084.      Some equations will be more readable using the "long" notation, while
  1085.      others will be a natural fit for the "short" version. There is no need
  1086.      to dogmatically rely upon one or the other.
  1087.  
  1088.      MIXING WILD CARD CODES
  1089.      Wild card codes can be intermixed in an equation. For instance, the
  1090.      following equation will convert a comma, a space, two upper case
  1091.      letters, and five numbers into: a comma, a space, two upper case
  1092.      letters, two spaces, and five numbers:
  1093.  
  1094.           , \u\u\n\n\n\n\n=, \p2\p3  *(5)\p4
  1095.  
  1096.      So if this string of characters was encountered in the data stream:
  1097.  
  1098.           , MN55044
  1099.  
  1100.      ...the equation would convert it to:
  1101.  
  1102.           , MN  55044
  1103.  
  1104.      CONVERTING SHIFT CASE
  1105.      Aside from \p, two other wild card codes can be used in a replacement
  1106.      string. Their purpose is to alter the shift case of an alphabetic
  1107.      character. The codes are \u and \y, for upper and lower conversion. As
  1108.      an example, we can make the sample equation dealing with the state and
  1109.      zip code used earlier a lot more universal with these new replacement
  1110.      wild cards:
  1111.  
  1112.           , \x\x\n\n\n\n\n=, \u2\u3  *(5)\p4
  1113.  
  1114.  
  1115.  
  1116.  
  1117.                                       -18-                    SNR+ VER 5.03
  1118.  
  1119.  
  1120.      This new equation will convert a comma, a space, two alphabetic
  1121.      characters of undetermined case, and five numbers into: a comma, a
  1122.      space, two upper case characters, two spaces, and five numbers.
  1123.  
  1124.      So if the following items were encountered in the data stream:
  1125.  
  1126.           , MN55044
  1127.           , Ny10022
  1128.           , il60301
  1129.           , nJ07680
  1130.  
  1131.      ...the equation would convert them to:
  1132.  
  1133.           , MN  55044
  1134.           , NY  10022
  1135.           , IL  60301
  1136.           , NJ  07680
  1137.  
  1138.      Here is set of equations that will convert a text file that is
  1139.      entirely in upper case into one that consists of upper and lower case,
  1140.      in sentence style:
  1141.  
  1142.           \u*00=\p0*01
  1143.           \u*01=\y0
  1144.           .=.*00
  1145.  
  1146.      In this equation, when an upper case letter is encountered in the data
  1147.      stream, and flag 0 is OFF, it is output as-is and flag 0 is set ON. If
  1148.      an upper case letter is encountered and flag 0 is ON, it is converted
  1149.      to a lower case letter. If a period is encountered, it is output as-is
  1150.      and flag 0 is set OFF, so the next upper case letter will be output
  1151.      as-is. Any other characters in the file will be passed through as-is.
  1152.  
  1153.      From this example data stream:
  1154.  
  1155.           NOW IS THE TIME. FOR ALL GOOD MEN. TO COME TO THE AID.
  1156.  
  1157.      ...the equation would produce:
  1158.  
  1159.           Now is the time. For all good men. To come to the aid.
  1160.  
  1161.      How would you alter the above small table to convert a file from all
  1162.      upper case to initial upper case, where the first letter of each word
  1163.      is capitalized? Stated another way, what character appears before each
  1164.      word that could be used to control the flag? Here's the answer:
  1165.  
  1166.           \u*00=\p0*01
  1167.           \u*01=\y0
  1168.           .=.*00
  1169.           \20=\20*00
  1170.  
  1171.      Just by adding the last line to the equation, a space will set flag 0
  1172.      to OFF, forcing the next character to be output as upper case.
  1173.  
  1174.      Now the previous sample data stream will be converted to:
  1175.  
  1176.           Now Is The Time. For All Good Men. To Come To The Aid.
  1177.  
  1178.  
  1179.                                       -19-                    SNR+ VER 5.03
  1180.  
  1181.  
  1182.  
  1183.      WILD CARDS AND \s
  1184.      You can use wild cards in conjunction with the \s start-of-file code
  1185.      to remove a number of characters from the beginning of a file:
  1186.  
  1187.           \s*(256)\p=
  1188.  
  1189.      The above equation will remove the first 256 characters (of any type)
  1190.      from a file.
  1191.  
  1192.      BEWARE OF SIDE EFFECTS
  1193.      Wild card codes are powerful tools. They can also be powerfully
  1194.      troublesome if not used with care. Keep in mind that these wild card
  1195.      codes have a hierarchy of pattern-matching: they range from highly
  1196.      inclusive to highly restrictive. If you have two or more wild card
  1197.      equations in your table, be keen to the possibility that one of the
  1198.      equations might end up taking precedence over another, leading to
  1199.      unintended conversions.
  1200.  
  1201.      SNR bases its pattern-matching tests on the total length of search
  1202.      equations. That is, for any string in the data stream that could
  1203.      potentially match two or more table equations, the equation that is
  1204.      longest will be tried first. The next longest one will be next, and so
  1205.      on down the line until no further equations meet the pattern in the
  1206.      data stream item.
  1207.  
  1208.      So, for any two equations that begin with the same character, the
  1209.      longer one will be tested before the shorter one. If the longer one
  1210.      happens to match the data stream pattern, it is replaced immediately,
  1211.      and none of the other equations will be tested.
  1212.  
  1213.      If two wild card equations have the same search string length but
  1214.      begin with a different wild card code, the equation with the wild card
  1215.      code that is more restrictive will be tested first. That is, if an
  1216.      equation beginning with \x and one beginning with \v are both the same
  1217.      length, the one beginning with \x will be tested against the data
  1218.      stream first, because the set of alphabetic characters is more
  1219.      exclusive than the set of all printable characters.
  1220.  
  1221.      Design your wild card search strings carefully to take this behavior
  1222.      into consideration, and your conversions will be more successful.
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.                                       -20-                    SNR+ VER 5.03
  1242.  
  1243.  
  1244.                           VARIABLE-LENGTH CONVERSIONS
  1245.  
  1246.      Up to now, the conversions that we have been discussing have dealt
  1247.      with fixed-length patterns of characters: some number of characters in
  1248.      a search string gets converted to some other number of characters in a
  1249.      replacement string, and we have been able to specifically count the
  1250.      number of characters on either side of the equation.
  1251.  
  1252.      Now we are going to explore the method SNR has of defining repeating
  1253.      characters or wild card codes whose actual number is unknown. These
  1254.      types of equations are called "variable-length" conversions.
  1255.  
  1256.      Variable-length conversions are used when you want to search on some
  1257.      identifiable set of characters -- maybe a line of text, maybe a
  1258.      phrase, maybe a command parameter -- but you don't know HOW MANY
  1259.      characters will be involved in the actual pattern.
  1260.  
  1261.      For instance, a line of text might contain one word, or it might
  1262.      contain fifty words. An imbedded text command might contain one
  1263.      parameter, or it might contain twelve parameters. A comma-delimited
  1264.      database field might contain ten characters, or it might contain
  1265.      twenty-five characters.
  1266.  
  1267.      The one thing that these types of text patterns -- a line, a
  1268.      parameter, a field -- have in common is that we wish to treat each of
  1269.      them as a unit, even though we don't know how many characters they
  1270.      will contain.
  1271.  
  1272.      Using variable-length conversions, you can define these higher-level
  1273.      units of data and translate them, throw them away, or rearrange them
  1274.      as needed.
  1275.  
  1276.      SEARCH STRING FUNDAMENTALS
  1277.      A variable-length string is declared to be a set of a specific type of
  1278.      character (literal or wild card) that matches from zero to a stated
  1279.      maximum length of similar characters in the data stream.
  1280.  
  1281.      Since variable-length search strings are basically unspecified lengths
  1282.      of similar characters, we can draw upon the notation that we
  1283.      prescribed earlier for the repeating-character strings:
  1284.  
  1285.           *(40)\20
  1286.  
  1287.      The above portion of a search string should be familiar to you as the
  1288.      definition for 40 spaces. To turn this into a variable-length
  1289.      definition, we add the \^ variable-length code:
  1290.  
  1291.           \^*(40)\20
  1292.  
  1293.      This search string fragment now defines "up to" 40 spaces. Likewise,
  1294.      the following fragment defining a string of 25 alphabetic characters:
  1295.  
  1296.           *(25)\x
  1297.  
  1298.      ...can be redescribed in variable-length terms like this:
  1299.  
  1300.           \^*(25)\x
  1301.  
  1302.  
  1303.                                       -21-                    SNR+ VER 5.03
  1304.  
  1305.  
  1306.  
  1307.      This search fragment now defines a string of "up to" 25 alphabetic
  1308.      characters.
  1309.  
  1310.      It is important to adhere to the following rules when you use
  1311.      variable-length search strings:
  1312.  
  1313.           - An equation cannot begin with a variable-length search string.
  1314.           - Each variable-length search string must be followed by a fixed-
  1315.             length terminator string.
  1316.  
  1317.      These restrictions are not quite so arbitrary as they may seem. As for
  1318.      the first rule, each equation must have some character or set of
  1319.      characters of fixed length that can begin the search pattern. The
  1320.      variable-length string can come right after this. As for the second
  1321.      rule, there must be something to tell SNR when the end of a variable-
  1322.      length string has been met; some specific character or set of
  1323.      characters must be defined that can act as a terminator to the
  1324.      variable-length string. The second rule also implies that the search
  1325.      side of an equation cannot end with a variable-length string.
  1326.  
  1327.      So here is a complete example of a valid variable-length search
  1328.      string:
  1329.  
  1330.           \v\^*(80)\v\0d\0a=
  1331.  
  1332.      Look at the equation. It defines: a printable character followed by up
  1333.      to 80 more printable characters terminated by a carriage return/line
  1334.      feed, to be thrown away. The effect of this equation will be to throw
  1335.      away full lines that are less than 82 characters long, or to throw
  1336.      away the last 82 characters of a longer line.
  1337.  
  1338.      Multiple variable-length strings can appear in an equation:
  1339.  
  1340.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=
  1341.  
  1342.      The above equation will search for: a quote followed by up to 30
  1343.      printable characters followed by a quote-comma-quote terminator
  1344.      followed by up to 30 more printable characters followed by another
  1345.      quote-comma-quote terminator followed by up to 30 more printable
  1346.      characters terminated by a quote and carriage return/line feed, and
  1347.      throw it all away. You may recognize this particular pattern as being
  1348.      characteristic of the comma-delimited ASCII file that many database
  1349.      and mail-merge programs support.
  1350.  
  1351.      The two examples we used above employed literal characters as
  1352.      terminator strings. It is equally valid to use wild card codes as
  1353.      terminator strings:
  1354.  
  1355.           \n\^*(20)\n\t=
  1356.  
  1357.      The above equation defines a number followed by up to 20 more numbers
  1358.      followed by a punctuation character to be thrown away.
  1359.  
  1360.      When you use wild card codes as a terminator to a variable-length
  1361.      string which itself uses wild cards, remember the earlier admonition
  1362.      concerning the hierarchy of wild card pattern matching. It applies
  1363.  
  1364.  
  1365.                                       -22-                    SNR+ VER 5.03
  1366.  
  1367.  
  1368.      equally here. Specifically, a wild card terminator must be more
  1369.      restrictive in type than the variable-length wild card string it is
  1370.      terminating.
  1371.  
  1372.      For instance, the following variable-length string is invalid:
  1373.  
  1374.           \n\^*(10)\n\p=
  1375.  
  1376.      The \p code used as the terminator has a higher inclusion value than
  1377.      the \n code. The result will be that this equation will generate
  1378.      incorrect output, if indeed it outputs anything at all.
  1379.  
  1380.      REPLACEMENT STRING FUNDAMENTALS
  1381.      The prior discussion concerned itself exclusively with the procedures
  1382.      for defining the search side of an equation. Now we will turn our
  1383.      attention to defining the replacement side of a variable-length
  1384.      equation.
  1385.  
  1386.      Since we don't know the actual number of characters that a variable-
  1387.      length string will pick up, it is not possible to use the \p notation
  1388.      to identify precise character positions for output. Instead, we
  1389.      identify groups of variable-length strings by the positions of the
  1390.      group: the first variable-length string on the search side is number
  1391.      one, the next such string in the equation is number two, and so on.
  1392.      (This is in contrast to the \p code, which begins at zero.)
  1393.  
  1394.      Up to 40 variable-length strings may be entered in a single equation.
  1395.  
  1396.      The variable-length replacement strings are defined as \^1, \^2, \^3
  1397.      and so on. Let's take an example based on the comma-delimited ASCII
  1398.      file, used earlier:
  1399.  
  1400.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=\^1\09\^2\09\^3\0d\0a
  1401.  
  1402.      While the search side of the equation remains the same as before, we
  1403.      have now introduced the replacement side. The replacement will be the
  1404.      first variable-length string followed by a tab code (the hex 09)
  1405.      followed by the second variable-length string followed by a tab code
  1406.      followed by the third variable-length string followed by a carriage
  1407.      return/line feed. The effect of this equation will be to convert a
  1408.      comma-quote delimited file into a tab-delimited file. (Digression: for
  1409.      purposes of illustration this example is fine, but is there a better
  1410.      way to accomplish the same result? The answer appears in a later
  1411.      section.)
  1412.  
  1413.      You may have observed by insight that it is possible to rearrange the
  1414.      strings by changing the order in which they appear on the replacement
  1415.      side of the equation. The procedure is straightforward and obvious, so
  1416.      I won't bother with an illustration.
  1417.  
  1418.      How do you output a wild card character that has been defined as a
  1419.      terminator? Since you can't pick the character out of the data stream
  1420.      by exact position, SNR provides a notation that describes a terminator
  1421.      string. Since each variable-length string in an equation is numbered
  1422.      from 1 to 40, and by definition each variable-length string must be
  1423.      followed by a terminator string, it makes sense that the terminator
  1424.      strings are also numbered from 1 to 40.
  1425.  
  1426.  
  1427.                                       -23-                    SNR+ VER 5.03
  1428.  
  1429.  
  1430.  
  1431.      The replacement notation for terminator strings is \^:1, \^:2, \^:3
  1432.      and so on (the colon being the only difference between them and the
  1433.      variable-length string identifier).
  1434.  
  1435.      Now having some way of differentiating between variable-length strings
  1436.      and terminators, we can convert equations such as the following:
  1437.  
  1438.           \u\^*(15)\y\u\^*(15)\y\t=\p0\^1\^:1\20\^2\^:2
  1439.  
  1440.      This admittedly contrived example serves to illustrate the placement
  1441.      and usage of the various codes. The search side defines an upper case
  1442.      character followed by up to 15 lower case characters terminated by an
  1443.      upper case character followed by up to 15 more lower case characters
  1444.      terminated by a punctuation character. The replacement side outputs
  1445.      the first character of the string (the first \u on the search side)
  1446.      followed by the first variable-length string followed by the first
  1447.      terminator followed by a space followed by the second variable-length
  1448.      string followed by the second terminator.
  1449.  
  1450.      For a concrete example, assume that this string occurs in the data
  1451.      stream:
  1452.  
  1453.           SuperDuper! UnquestionablyAwesome.
  1454.  
  1455.      Our example equation will convert it to this:
  1456.  
  1457.           Super Duper! Unquestionably Awesome.
  1458.  
  1459.      Let's try switching the order of a few elements in the equation:
  1460.  
  1461.           \u\^*(15)\y\u\^*(15)\y\t=\^:1\^2\20\p0\^1\^:2
  1462.  
  1463.      The search side remains the same; the replacement side has changed.
  1464.      Study it and see if you can follow the meaning. Perhaps this will
  1465.      help: given the same example data stream as above, the altered
  1466.      equation will produce this output:
  1467.  
  1468.           Duper Super! Awesome Unquestionably.
  1469.  
  1470.      PADDING VARIABLE-LENGTH STRINGS
  1471.      A specialized use of variable-length replacement strings allows the
  1472.      strings to be padded out to their maximum width. Normally, of course,
  1473.      the strings are output to their "natural" width -- however many
  1474.      characters are contained in the data stream are what gets output
  1475.      during replacement.
  1476.  
  1477.      Padding the strings adds blank spaces to the left or right of the text
  1478.      proper, and has the effect of aligning the text within a field that is
  1479.      as wide as the maximum width specified in the variable-length search
  1480.      string.
  1481.  
  1482.      To invoke variable-length padding, the alignment codes R and L are
  1483.      inserted before the variable-length string number in a replacement
  1484.      string. For instance, \^L1 will left-align the first variable-length
  1485.      string; \^R3 would right-align the third variable-length string.
  1486.      Here's how the codes are used in an equation:
  1487.  
  1488.  
  1489.                                       -24-                    SNR+ VER 5.03
  1490.  
  1491.  
  1492.  
  1493.           "\^*(30)\v","\^*(30)\v","\^*(30)\v"\0d\0a=\^L1\^L2\^R3\0d\0a
  1494.  
  1495.      Taking our well-worn comma-delimited example yet again, pay particular
  1496.      attention to the replacement side. Those codes specify that the first
  1497.      variable-length string will be output left-aligned to a width of 30
  1498.      characters, the second variable-length field will be output left-
  1499.      aligned to a width of 30 characters, and the third variable-length
  1500.      field will be output right-aligned to a width of 30 characters
  1501.      followed by a carriage return/line feed. What we have done in this
  1502.      example is converted a file containing comma-delimited fields into a
  1503.      file containing fixed-length fields.
  1504.  
  1505.      The widths of the fields can be changed simply by changing the width
  1506.      values in the search strings:
  1507.  
  1508.           "\^*(35)\v","\^*(25)\v","\^*(40)\v"\0d\0a=\^L1\^L2\^R3\0d\0a
  1509.  
  1510.      In this case, the replacement side of the equation is the same as
  1511.      before, but the search side now contains different widths for each of
  1512.      the fields. This will affect the appearance of the output when the
  1513.      text is padded; it will not affect the appearance of the text if the
  1514.      alignment codes are removed.
  1515.  
  1516.      PAD CHARACTER
  1517.      By default, variable-length strings are padded with spaces when the R
  1518.      or L alignment codes are specified. You can select a different padding
  1519.      character by placing the setup code \\Axx at the beginning of your
  1520.      table, where "xx" is a hex value representing the character you wish
  1521.      to use as the padding character. Only one padding character may be
  1522.      defined per table, and once selected, it can not be changed.
  1523.  
  1524.      As an example, you could pad your variable-length text strings with
  1525.      periods by using the setup code:
  1526.  
  1527.           \\A2E
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.                                       -25-                    SNR+ VER 5.03
  1552.  
  1553.  
  1554.                                  HINTS AND TIPS
  1555.  
  1556.      The conversion capabilities of SNR are very sophisticated. Some of
  1557.      them are subtle, and require some study and experimentation to master.
  1558.      Here is a list of a few pointers that might help you avoid the
  1559.      pitfalls of inexperience.
  1560.  
  1561.      1.   Lots of smaller tables are better than one large table.
  1562.  
  1563.           It is sometimes tempting to create a huge, do-it-all conversion
  1564.           table that takes care of your conversion task all at once. Let me
  1565.           tell you from experience that it is much better to break down
  1566.           your conversion into a series of smaller tables that are run one
  1567.           after the other.
  1568.                One reason behind this is that it is much simpler to
  1569.           pinpoint problems when you take your conversion a little bit at a
  1570.           time, and you won't waste your energy poking around a large table
  1571.           feebly trying to discover why your text isn't converting the way
  1572.           you thought it should.
  1573.                Remember that SNR allows you to run up to 20 tables at one
  1574.           time on the command line anyway, giving you the same benefit as
  1575.           having one large table.
  1576.                Another reason to break your task into smaller pieces is
  1577.           that some of the more advanced conversion models -- such as
  1578.           variable-length strings -- may have unwanted side effects on
  1579.           other equations or vice versa. It is safer to isolate the complex
  1580.           portions of a conversion task into their own tables to insure
  1581.           that harmful side effects are not introduced.
  1582.  
  1583.      2.   Use literal characters over wild cards wherever possible.
  1584.  
  1585.           Wild cards are very powerful, but they require much more time to
  1586.           process than literal characters. Whenever you can, it is
  1587.           preferable to define conversion equations using literal
  1588.           characters instead of wild cards.
  1589.                If your conversion task can be represented by a few well-
  1590.           defined data patterns, it's a good candidate for literal
  1591.           equations. If, on the other hand, you have a particular need to
  1592.           search a wide range of data patterns, then the wild card equation
  1593.           is your best choice.
  1594.                Remember the question I posed back in the variable-length
  1595.           section? I asked if there was a better way than using variable-
  1596.           length strings to convert a comma-delimited text file into a tab-
  1597.           delimited text file. The answer is yes. If you think about it a
  1598.           little bit, there is no real need to do any conversion of the
  1599.           data within the delimiters at all. Only the delimiters themselves
  1600.           need to be converted. So rather than chewing up a lot of CPU
  1601.           cycles scanning the data stream for variable-length text, the
  1602.           following two equations will perform the conversion much faster:
  1603.  
  1604.                "=
  1605.                ","=\09
  1606.  
  1607.           An added benefit to using this table over the other one is that
  1608.           this version does not need to be modified when the number of
  1609.           fields changes, whereas the other one does. I guess this is one
  1610.           of those situations where Less Is More.
  1611.  
  1612.  
  1613.                                       -26-                    SNR+ VER 5.03
  1614.  
  1615.  
  1616.  
  1617.      3.   Use context flags rather than variable-length patterns when you
  1618.           are seeking to compress the data stream.
  1619.  
  1620.           This is another issue related to efficiency. Variable-length
  1621.           conversion strings provide a means of reading an unspecified
  1622.           number of consecutive characters and eliminating them, in effect
  1623.           compressing the data stream. But equations using context flags
  1624.           such as *ic or *ig provide a much faster conversion than
  1625.           variable-length equations.
  1626.  
  1627.      4.   Debug your tables an equation at a time.
  1628.  
  1629.           Debugging is a cross between an art and a science; it requires
  1630.           both discipline and inspiration to do it well. The first step in
  1631.           effective debugging is to find the trouble spot and focus your
  1632.           attention on it.
  1633.                The easiest way to do this in SNR is to place a comment code
  1634.           (backslash followed by a space) in front of every equation in
  1635.           your table, and enable each equation one at a time. Test a sample
  1636.           of your data file for each new equation that you enable.
  1637.           Eventually, you will hit upon the one equation that is fouling
  1638.           things up, and you will be able to alter it or isolate it by
  1639.           moving it to another table, where it can be dissected and
  1640.           analyzed apart from other equations.
  1641.                Once the trouble equation has been found, look at it
  1642.           carefully. Consider these questions:
  1643.                - Are you sure it is defined according to the rules set
  1644.                  forth in this document?
  1645.                - Does each element of the equation logically match a likely
  1646.                  pattern in the data stream?
  1647.                - Are your wild card definitions too vague to match a
  1648.                  specific pattern in the data stream?
  1649.                - Are there any possible conflicts between elements of the
  1650.                  equation that would render it invalid?
  1651.                - Can the equation be restated equivalently in different
  1652.                  terms, that is, using a different conversion model (for
  1653.                  example, transforming wild cards into literals)?
  1654.                - Is what you are trying to do reasonable or even possible
  1655.                  in the SNR conversion paradigm?
  1656.                - Have you done something like this before and made it work?
  1657.                - Is there a similar equation shown in the sample tables?
  1658.                - Could there be a bug in SNR?
  1659.                Seeking the answers to these questions will help guide your
  1660.           troubleshooting steps in a logical, scientific manner.
  1661.  
  1662.      5.   Use lots of comments.
  1663.  
  1664.           This point was brought up in the first section of the manual, but
  1665.           it bears repeating. 'Nuff said.
  1666.  
  1667.      6.   Peruse the provided example tables.
  1668.  
  1669.           The range of possible uses of SNR, and the examples to support
  1670.           them, are beyond the scope of this manual. Many of the more
  1671.           complex and subtle uses of conversion strings can only be
  1672.  
  1673.  
  1674.  
  1675.                                       -27-                    SNR+ VER 5.03
  1676.  
  1677.  
  1678.           appreciated by experimentation or by looking through the example
  1679.           tables provided in the archive file.
  1680.                The tables may help provide you with hints on syntax and
  1681.           usage that this manual was unable to. If you register the
  1682.           program, you will be entitled to telephone or on-line support
  1683.           (toll at your expense) and I will be happy to help you solve your
  1684.           conversion problems.
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.                                       -28-                    SNR+ VER 5.03
  1738.  
  1739.  
  1740.                                  MISCELLANEOUS
  1741.  
  1742.      BIT STRIPPING
  1743.      In prior versions of SNR, the default action was to map all incoming
  1744.      characters to 7-bit ASCII before running them through the equations.
  1745.      In version 5, this has been changed: no "bit-stripping" is performed
  1746.      by default. If you wish to have your table map incoming characters to
  1747.      a 7-bit ASCII set, you must enter the \\L7 setup code at the beginning
  1748.      of your table.
  1749.  
  1750.      NOTES
  1751.      The program will run on any IBM-compatible computer using DOS 3.0 or
  1752.      higher, with a minimum of 512K RAM.
  1753.  
  1754.      SNR was written in Borland C++ 3.1.
  1755.  
  1756.      DISCLAIMER
  1757.      This program is distributed as shareware. Use it, copy it, upload it,
  1758.      give it to your friends. Please distribute only the complete program
  1759.      in archived form, including all document and sample files. No
  1760.      warranties, either expressed or implied, are given by the author or
  1761.      distributor of the program, and the user accepts all risk of damage
  1762.      arising out of the application and use of the program.
  1763.  
  1764.      REGISTRATION
  1765.      If you like SNR, please register your copy for $50. At that price,
  1766.      it's one of the bargains of the text processing world, and I'll bet
  1767.      you recoup that investment dozens, maybe hundreds, of times over in
  1768.      the work it will save you.
  1769.  
  1770.      Registered users will receive a version of the program that does not
  1771.      have the compliance delay screen. Also included FREE with the
  1772.      registered version is TurboEdit, a DOS text editor that provides a
  1773.      multiple-window, mouse-supported editing environment with a built-in
  1774.      ASCII table and calculator (very useful for editing your conversion
  1775.      tables).
  1776.  
  1777.      Please fill out and return with your payment the form in the file
  1778.      ORDER.FRM.
  1779.  
  1780.      Registered users are guaranteed a response to technical support
  1781.      questions by phone, mail, or CompuServe. Unregistered users will
  1782.      receive responses on a time-available basis, but I can't guarantee
  1783.      that I will respond to those requests.
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.                                       -29-                    SNR+ VER 5.03